package com.michaellou.FpComint;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import com.foolfish.comintc.client.FPIOConnector;
import com.foolfish.comintc.client.FPInetAddress;
import com.foolfish.comintc.exception.FPComException;



public class Client {
	/**
	 * @param args
	 * @throws com.foolfish.comintc.exception.FPComException 
	 * @throws IOException 
	 * @throws FPComException 
	 */
	public static void main(String[] args){
		String line = "Hello";
		int i = 0;
		int j = 0;
		while(true){
			try {
				// 设置服务端的地址和端口号
				FPIOConnector conn = new FPIOConnector(true, new FPInetAddress("127.0.0.1", 4331));
				// 设定自动重发次数（对于延迟等错误情况可以选择自动重发）
				conn.setRetryCount(2);
				// 发送并接收返回的结果信息，并统计错误率
				System.out.println(new String(conn.request(line.getBytes("utf-8")),"utf-8")+"共请求"+(i++)+"次，错误"+(j)+"次");
			}catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			} catch (FPComException e) {
				j++;
			    continue;
			}
		}
	}
}
